package top.ruanlitao.shortlink.project.config;

import cn.hutool.core.codec.Hashids;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Hashids 配置
 */
@Configuration
public class HashidsConfiguration {

    // 短链接生成加盐
    @Value("${app.short-url.hashids.salt:k4q=G-86.vR.9)mkhcKy}")
    private String hashidsSalt;

    // 短链接生成使用的 alphabet
    @Value("${app.short-url.hashids.alphabet:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789}")
    private String hashidsAlphabet;

    @Bean
    public Hashids hashids() {
        return Hashids.create(hashidsSalt.toCharArray(), hashidsAlphabet.toCharArray(), 5);
    }
}
